package com.multi.publicly.service.impl;

import com.multi.common.utils.SecurityUtils;
import com.multi.publicly.domain.WxUserInfo;
import com.multi.publicly.mapper.WxUserInfoMapper;
import com.multi.publicly.resp.WxUserInfoResp;
import com.multi.publicly.service.WxUserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description 微信用户操作接口实现
 * @ClassName WxUserInfoServiceImpl
 * @Author pzj
 * @Data 2024/12/3 11:37
 */
@Slf4j
@Service
public class WxUserInfoServiceImpl implements WxUserInfoService {

    @Autowired
    private WxUserInfoMapper wxUserInfoMapper;


    @Override
    public WxUserInfo selectByOpenId(String openId) {
        WxUserInfo wxUserInfo = wxUserInfoMapper.selectByOpenId(openId);
        return wxUserInfo;
    }

    @Override
    public int insertWxUserInfo(WxUserInfo wxUserInfo) {
        return wxUserInfoMapper.insertWxUserInfo(wxUserInfo);
    }

    @Override
    public WxUserInfo selectByUserId(Long id) {
        return wxUserInfoMapper.selectByUserId(id);
    }

    @Override
    public WxUserInfoResp getUserProfile() {
        Long userId = SecurityUtils.getWxUserId();
        WxUserInfo wxUserInfo = wxUserInfoMapper.selectByUserId(userId);
        WxUserInfoResp wxUserInfoResp = new WxUserInfoResp();
        BeanUtils.copyProperties(wxUserInfo,wxUserInfoResp);
        return wxUserInfoResp;
    }
}
